
	/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}baseline_for figures.dta"
	CREATES:	${out_tables}/T1A_basebalance_lang.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "$dt_int/baseline_for figures.dta", clear


	* Establish macros for regressions



/*******************************************************************************
	Table A1: Baseline Balance: Child Receptive and Expressive Language
*******************************************************************************/
	* Rename relevant variables
	*---------------------------------

	
	gen Evalplsivtot3=. 
    replace Evalplsivtot3=1 if t_per<=2 & t_per!=.
    replace Evalplsivtot3=2 if inrange(t_per,3,15) & t_per!=.
	replace Evalplsivtot3=3 if t_per>=16 & t_per!=.
	gen Evalplsivaud3=. 
    replace Evalplsivaud3=1 if  percentil_aud<=2 & t_per!=.
    replace Evalplsivaud3=2 if inrange( percentil_aud,3,15) & t_per!=.
	replace Evalplsivaud3=3 if  percentil_aud>=16 & t_per!=.
	gen Evalplsivexp3=. 
    replace Evalplsivexp3=1 if  percentil_e<=2 & t_per!=.
    replace Evalplsivexp3=2 if inrange( percentil_e,3,15) & t_per!=.
	replace Evalplsivexp3=3 if  percentil_e>=16 & t_per!=.
	tabulate Evalplsivtot3, g(plst)
	tabulate Evalplsivaud3, g(plsa)
	tabulate Evalplsivexp3, g(plse)
	g t_score_rec=ss_audi_PLSIV if t_per!=.
	g t_score_exp=ss_expre_PLSIV if t_per!=.

	* CBCL
	tabstat  ach_ttot, by(TIPO) s(mean sd)
	tabstat  ach_tint, by(TIPO) s(mean sd)
	tabstat  ach_text, by(TIPO) s(mean sd)

	tabulate ach_tot_3lev, g(acht)
	tabulate ach_int_3lev, g(achi)
	tabulate ach_ext_3lev, g(ache)

	*DCCS
	forvalues i=3/6 {

	g DCCSPunt`i'=DCCSPunt_old if  edadtramos==`i'
	g DCCS_pass`i'=DCCS_pass_old if  edadtramos==`i'
	tabulate DCCS_pass`i', g(dccs`i')

	}



iebaltab t_score_old t_score_rec t_score_exp plst1 plst2 plst3,  grpvar(TIPO) save("${out_tables}/appendix/T1A_basebalance_lang.xlsx") ftest fmissok pttest pftest total replace
import excel using "${out_tables}/appendix/T1A_basebalance_lang.xlsx", clear
drop L 
gen row = _n 
replace A = "Global score" if row == 4
replace A = "Receptive Language score" if row == 6 
replace A = "Expressive Language score" if row == 8 



replace A = "Clinical range (%)" if row == 10
replace A = "Risk (%)" if row == 12
replace A = "Normal (%)" if row == 14 
	
drop row

export  excel using "${out_tables}/appendix/T1A_basebalance_lang.xlsx", replace
